package com.zcx.qshop.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.qshop.R;

/**
 * Created by Administrator on 2015/8/22 0022.
 */
public class OrderBarView extends LinearLayout implements View.OnClickListener{

    @BoundView(R.id.view_order_bar_all) private ViewGroup all;

    @BoundView(R.id.view_order_bar_pay) private ViewGroup pay;

    @BoundView(R.id.view_order_bar_assess) private ViewGroup assess;

    @BoundView(R.id.view_order_bar_assessed) private ViewGroup assessed;

    @BoundView(R.id.view_order_bar_refund) private ViewGroup refund;

    private OnItemClickListener onItemClickListener;

    public OrderBarView(Context context, AttributeSet attrs) {

        super(context, attrs);

        BoundViewHelper.boundView(this, LayoutInflater.from(context).inflate(R.layout.view_order_bar, this));

        all.setOnClickListener(this);

        pay.setOnClickListener(this);

        assess.setOnClickListener(this);

        assessed.setOnClickListener(this);

        refund.setOnClickListener(this);

    }

    private void setState(ViewGroup viewGroup, boolean isState){

        ((TextView)viewGroup.getChildAt(0)).setTextColor(getContext().getResources().getColor(isState ? R.color.dominant_tone_one : R.color.dominant_tone_two));

        viewGroup.getChildAt(1).setVisibility(isState ? View.VISIBLE : View.INVISIBLE);

    }

    @Override
    public void onClick(View v) {

        setState(all, false);

        setState(pay, false);

        setState(assess, false);

        setState(assessed, false);

        setState(refund, false);

        setState((ViewGroup) v, true);

        switch(v.getId()){

            case R.id.view_order_bar_all:

                onItemClickListener.onItemClick("all");

                break;

            case R.id.view_order_bar_pay:

                onItemClickListener.onItemClick("1");

                break;

            case R.id.view_order_bar_assess:

                onItemClickListener.onItemClick("7");

                break;

            case R.id.view_order_bar_assessed:

                onItemClickListener.onItemClick("8");

                break;

            case R.id.view_order_bar_refund:

                onItemClickListener.onItemClick("-10");

                break;

        }

    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){

        this.onItemClickListener = onItemClickListener;

        onClick(all);

    }

    public interface OnItemClickListener{

        void onItemClick(String type);

    }

}
